<!-- 筛选期判断公用组件 -->

<template>
	<div style="position: relative">
		<el-row style="position: absolute; top: -24px; left: 0px; right: 0">
			<el-col :span="12">
				<span
					style="
						line-height: 20px;
						height: 20px;
						display: inline-block;
						cursor: pointer;
					"
					v-if="leftShow"
					@click="leftShow = !leftShow"
				>
					<i
						class="el-icon-s-fold"
						style="font-size: 20px; cursor: pointer; float: left"
					></i
					><label style="display: inline-block; cursor: pointer"
						>（点击收缩）</label
					>
				</span>
				<span
					style="
						line-height: 20px;
						height: 20px;
						display: inline-block;
						cursor: pointer;
					"
					v-if="!leftShow"
					@click="leftShow = !leftShow"
				>
					<i
						class="el-icon-s-unfold"
						style="
							font-size: 20px;
							cursor: pointer;
							float: left;
							cursor: pointer;
						"
					></i
					><label style="display: inline-block; cursor: pointer"
						>（点击展开）</label
					>
				</span>
			</el-col>
			<el-col :span="12">
				<span
					style="
						line-height: 20px;
						height: 20px;
						display: inline-block;
						cursor: pointer;
					"
					v-if="!rightShow"
					@click="rightShow = !rightShow"
				>
					<i
						class="el-icon-s-fold"
						style="font-size: 20px; cursor: pointer; float: left"
					></i
					><label style="display: inline-block; cursor: pointer"
						>（点击展开）</label
					>
				</span>
				<span
					style="
						line-height: 20px;
						height: 20px;
						display: inline-block;
						cursor: pointer;
					"
					v-if="rightShow"
					@click="rightShow = !rightShow"
				>
					<i
						class="el-icon-s-unfold"
						style="font-size: 20px; cursor: pointer; float: left"
					></i
					><label style="display: inline-block; cursor: pointer"
						>（点击收缩）</label
					>
				</span>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="leftShow ? (rightShow ? 12 : 24) : 0">
				<el-tabs tab-position="top" @tab-click="tabClick">
					<el-tab-pane label="入选/排除标准"></el-tab-pane>
					<el-tab-pane label="筛选判断"></el-tab-pane>
				</el-tabs>
				<div v-if="curTab == 0">
					<el-row>
						<el-col :span="4" style="line-height: 32px">
							<i class="el-icon el-icon-d-arrow-right"></i> 入选标准
						</el-col>
						<el-col :span="20" v-if="oprType != 'view'">
							<el-button
								@click="setValue(item, 1)"
								size="small"
								v-for="(item, index) in selectList"
								v-bind:key="index"
								>一键[{{ item.label }}]</el-button
							>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<div style="max-height: 250px">
								<judge-table
									:dataSource="contentData1"
									ref="judgeTable1"
									:oprType="oprType"
								></judge-table>
							</div>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="4" style="line-height: 32px">
							<i class="el-icon el-icon-d-arrow-right"></i> 排除标准
						</el-col>
						<el-col :span="20" v-if="oprType != 'view'">
							<el-button
								@click="setValue(item, 2)"
								size="small"
								v-for="(item, index) in selectList"
								v-bind:key="index"
								>一键[{{ item.label }}]</el-button
							>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24">
							<div style="max-height: 250px">
								<judge-table
									:dataSource="contentData2"
									ref="judgeTable2"
									:oprType="oprType"
								></judge-table>
							</div>
						</el-col>
					</el-row>
				</div>
				<div v-else>
					<el-form
						label-width="120px"
						size="small"
						:disabled="oprType == 'view'"
					>
						<el-form-item label="是否合格" :prop="isPass">
							<!-- <el-select style="width: 100%" v-model="isPass">
								<el-option
									:label="select.label"
									:value="select.value.toString()"
									v-for="(select, sIndex) in passList"
									:key="sIndex"
								></el-option>
							</el-select> -->
							<el-radio-group v-model="isPass" style="display: inline">
								<el-radio
									:label="radioItem.value"
									v-for="radioItem in passList"
									v-bind:key="radioItem.value"
									>{{ radioItem.label }}</el-radio
								>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="备注" :prop="remarks">
							<el-input
								style="width: 100%"
								v-model="remarks"
								type="textarea"
							></el-input>
						</el-form-item>
						<el-form-item label="不合格原因" :prop="noPassReason">
							<el-input
								style="width: 100%"
								v-model="noPassReason"
								type="textarea"
							></el-input>
						</el-form-item>
					</el-form>
				</div>
			</el-col>
			<el-col
				:span="rightShow ? (leftShow ? 12 : 24) : 0"
				v-if="examineeInfo.id"
			>
				<screening-judge-tab
					:userInfo="examineeInfo"
					:type="type"
					:isFirst="isFirst"
				></screening-judge-tab>
			</el-col>
		</el-row>
		<el-row
			style="margin-top: 10px; text-align: right"
			v-if="oprType != 'view'"
		>
			<el-col :span="24">
				<el-button type="primary" size="small" @click="saveData"
					>确 定</el-button
				>
				<el-button size="small" @click="closeDialog">取 消</el-button>
			</el-col>
		</el-row>
	</div>
</template>

<script>
	import judgeTable from "@/components/customComponents/managementCenter/judgeTable"
	import { AjaxCommon } from "@/libs/apiCommon"
	import { PopupCommon } from "@/libs/popupCommon"
	import { Utility } from "@/libs/utility"
	import screeningJudgeTab from "./screeningJudgeTab"
	export default {
		components: {
			screeningJudgeTab,
			judgeTable,
		},
		data() {
			return {
				// 左侧默认展开
				leftShow: true,
				// 右侧默认展开
				rightShow: true,
				noPassReason: "",
				remarks: "",
				isPass: "",
				examineeCodeList: [],
				// 受试者信息
				examineeInfo: {},
				pageSize: 1000,
				pageNo: 1,
				// 筛选判断查询参数 begin
				examineeName: "",
				passList: Utility.getDictList("yn"),
				// 筛选判断查询参数 end
				curTab: 0,
				// 入选/排除标准
				selectList: Utility.getDictList("select_option"),
				contentData1: [],
				contentData2: [],
				rxData: [],
				pcData: [],
			}
		},
		// 这里的type是指筛选期还是入住期,isFirst:是否首次入住  oprType:操作类型默认新增，view 查看，这里暂时只做两种：新增和查看
		/**
		 * type=filter 筛选期
		 * type=in 入住期，首次入住
		 */
		props: ["userInfo", "type", "isFirst", "oprType"],
		methods: {
			closeDialog() {
				this.$emit("screeningJudgeClose", "1")
			},
			saveData() {
				if (this.$refs.judgeTable1) {
					this.rxData = this.$refs.judgeTable1.getData()
					this.pcData = this.$refs.judgeTable2.getData()
				}
				const rxData = this.rxData
				const pcData = this.pcData
				let rxIsTrue = true
				let pcIsTrue = true
				rxData.forEach((t) => {
					if (t.options == "") {
						rxIsTrue = false
					}
				})
				pcData.forEach((t) => {
					if (t.options == "") {
						pcIsTrue = false
					}
				})

				if (!rxIsTrue) {
					PopupCommon.notify("info", "请将入选标准选择完")
					return
				}
				if (!pcIsTrue) {
					PopupCommon.notify("info", "请将排除标准选择完")
					return
				}
				// 受试者信息
				const user = this.examineeInfo
				let resultList = []
				// 入选
				rxData.forEach((t) => {
					resultList.push({
						type: "入选标准",
						standardName: t.standardName,
						judgeResult: t.optionsName,
					})
				})
				// 排除
				pcData.forEach((t) => {
					resultList.push({
						type: "排除标准",
						standardName: t.standardName,
						judgeResult: t.optionsName,
					})
				})
				if (this.isPass == "") {
					PopupCommon.notify("info", "请选择筛选判断页签里的是否合格")
					return
				}
				const modal = {
					judgeTime: user.judgeTime,
					standardJudgeBy: user.standardJudgeBy,
					examineeName: user.examineeName,
					isPass: this.isPass,
					noPassReason: this.noPassReason,
					examineeEn: user.examineeEn,
					resultList: resultList,
					standardJudgeByName: user.standardJudgeByName,
					randomNo: user.randomNo,
					remarks: this.remarks,
					sex: user.sex,
					examineeCode: user.examineeCode,
					filterNo: user.filterNo,
				}
				let url =
					this.type == "filter"
						? "/ccdc/pm/em/filter/emFilterJudge/edit"
						: "/ccdc/pm/em/in/emInJudge/edit"
				AjaxCommon(url, "post", modal, this.isFirst).then((res) => {
					if (res.data.code == 200) {
						PopupCommon.notify("success", "操作成功")
						this.$emit("screeningJudgeClose", "1")
					} else {
						PopupCommon.notify("error", res.data.message)
					}
				})
			},
			tabClick(tab) {
				// 切换前获取值
				if (tab.paneName == 1) {
					this.rxData = this.$refs.judgeTable1.getData()
					this.pcData = this.$refs.judgeTable2.getData()
				}
				this.curTab = parseInt(tab.paneName)
			},
			/**
			 * 设置一键
			 * @param {*} item 字典对象
			 * @param {*} type 入住1/排除2
			 */
			setValue(item, type) {
				if (type == 1) {
					this.contentData1 = this.contentData1.map((t) => {
						t.optionsName = item.label
						t.options = item.value
						return t
					})
				} else {
					this.contentData2 = this.contentData2.map((t) => {
						t.optionsName = item.label
						t.options = item.value
						return t
					})
				}
			},
			getData() {
				let self = this
				let url1 =
					this.type == "filter"
						? "/ccdc/cfg/exp/filter/expFilterInclusionCriteria/listByPage"
						: "/ccdc/cfg/exp/in/expInInclusionCriteria/listByPage"
				let url2 =
					this.type == "filter"
						? "/ccdc/cfg/exp/filter/expFilterExcludeCriteria/listByPage"
						: "/ccdc/cfg/exp/in/expInExcludeCriteria/listByPage"
				let url3 =
					this.type == "filter"
						? "/ccdc/pm/em/filter/emFilterJudge/queryDetailList"
						: "/ccdc/pm/em/in/emInJudge/queryDetailList"

				// 入住数据       排除数据
				Promise.all([
					AjaxCommon(
						url1,
						"post",
						{
							type: "",
							pageNo: this.pageNo,
							pageSize: this.pageSize,
						},
						this.isFirst
					),
					AjaxCommon(
						url2,
						"post",
						{
							type: "",
							pageNo: this.pageNo,
							pageSize: this.pageSize,
						},
						this.isFirst
					),
					AjaxCommon(
						url3,
						"post",
						{ examineeCode: this.examineeInfo.examineeCode },
						this.isFirst
					),
				]).then((res) => {
					let data3 = res[2].data.result
					let data1 = res[0].data.result.records
					let judgeResult = ""
					data1 = data1.map((t) => {
						judgeResult = ""
						if (self.oprType == "view" && data3 && data3.length > 0) {
							judgeResult = data3.find(
								(b) => b.standardName == t.standardName && b.type == "入选标准"
							)
							if (judgeResult) {
								judgeResult = judgeResult.judgeResult
							}
						}
						t.options = judgeResult
						return t
					})
					self.contentData1 = data1
					let data2 = res[1].data.result.records
					console.log(data2, "data2..........")
					data2 = data2.map((t) => {
						judgeResult = ""
						if (self.oprType == "view" && data3 && data3.length > 0) {
							judgeResult = data3.find(
								(b) => b.standardName == t.standardName && b.type == "排除标准"
							)
							if (judgeResult) {
								judgeResult = judgeResult.judgeResult
							}
						}
						t.options = judgeResult
						return t
					})
					self.contentData2 = data2

					console.log(res[2], "res[2].......")
				})
			},
		},
		mounted() {
			this.examineeInfo = this.userInfo
			console.log(this.userInfo, "this.userInfo")
			if (this.oprType == "view") {
				this.noPassReason = this.userInfo.noPassReason
				// 看了返回的数据，好像少了这个字段
				this.remarks = this.userInfo.remarks
				this.isPass = this.userInfo.isPass
			}

			this.getData()
		},
	}
</script>

<style></style>
